<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>重复发送</title>
</head>

<body>
    <button>发送请求</button>
</body>
<script>
    const btn = document.querySelector('button');
    let x = null;
    let isSending = false; // 是否正在发送ajax请求
    btn.onclick = function() {
        // 判断标识变量,如果正在发送，则取消该请求，创建一个新的请求
        if (isSending) x.abort();
        x = new XMLHttpRequest();
        // 修改标识变量的值
        isSending = true;
        x.open('GET', 'http://127.0.0.1:8000/delay');
        x.send();
        x.onreadystatechange = function() {
            if (x.readystate === 4) {
                isSending = false;
            }
        }
    }
</script>

</html>